
$(function() {
	validateRule();

	//打开图标列表
    $("#ico-btn").click(function(){
        layer.open({
            type: 2,
			title:'图标列表',
            content: '../../../public/FontIcoList.html',
            area: ['480px', '90%'],
            success: function(layero, index){
                //var body = layer.getChildFrame('.ico-list', index);
                //console.log(layero, index);
            }
        });
    });

});
$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});
function update(id) {
var obj = $('#signupForm').serializeArray();
	var object = new Object();
	for(var i=0;i<obj.length;i++){
		object[obj[i].name] = obj[i].value;
	}
//var params = {};
// params.id = $('#id').val();
// params.name = $('#name').val();
// params.depotCode = $('#depotCode').val();
// params.depotType = $('#depotType').val();
// params.depotState = $('#depotState').val();
// params.architecture = $('#architecture').val();
// params.depotArea = $('#depotArea').val();
// params.depFloor = $('#depFloor').val();
// params.depAdmin = $('#depAdmin').val();
// params.depNumber = $('#depNumber').val();
	$.ajax({
		cache : true,
		type : "POST",
		dataType: 'json',
        contentType: 'application/json',
		headers:PRIVATE_HEADERS,
		url : API_SERVER_URL + "/res/depotT/update",
		data : JSON.stringify(object),// 你的formid
		async : false,
		error : function(request) {
			alert(JSON.stringify(request));
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("保存成功");
				window.parent.location.reload() ;
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				layer.alert(data.msg)
			}

		}
	});

}
function validate() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            name : {
                required : true
            },
            depotCode : {
                required : true
            },
            depotType : {
                required : true
            },
            depotState : {
                 required : true
             },
            architecture : {
                  required : true
              },
            areaName : {
               required : true
            },
            depFloor : {
                required : true
            },
            userName : {
                 required : true
            },
            depNumber : {
                 required : true
            }
        },
        messages : {
            name : {
                required : icon + "请输入库房名称"
            },
            depotCode : {
                 required : icon + "请输入库房编码"
            },
            depotType : {
                 required : icon + "请选择库房类型"
            },
            depotState : {
                 required : icon + "请选择库房状态"
            },
            architecture : {
                 required : icon + "请输入所属建筑"
            },
            areaName : {
                 required : icon + "请选择所属区域"
            },
            depFloor : {
                 required : icon + "请输入楼层"
            },
            userName : {
                 required : icon + "请选择库房管理员"
            },
            depNumber : {
                 required : icon + "请输入房间号"
            }
        }
	})
}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
            name : {
                required : true
            },
            depotCode : {
                required : true
            },
            depotType : {
                required : true
            },
            depotState : {
                 required : true
             },
            architecture : {
                  required : true
              },
            areaName : {
               required : true
            },
            depFloor : {
                required : true
            },
            userName : {
                 required : true
            },
            depNumber : {
                 required : true
            }
        },
        messages : {
            name : {
                required : icon + "请输入库房名称"
            },
            depotCode : {
                 required : icon + "请输入库房编码"
            },
            depotType : {
                 required : icon + "请选择库房类型"
            },
            depotState : {
                 required : icon + "请选择库房状态"
            },
            architecture : {
                 required : icon + "请输入所属建筑"
            },
            areaName : {
                 required : icon + "请选择所属区域"
            },
            depFloor : {
                 required : icon + "请输入楼层"
            },
            userName : {
                 required : icon + "请选择库房管理员"
            },
            depNumber : {
                 required : icon + "请输入房间号"
            }
        }
	})
}